package com.ruoyi.web.controller.invoice.dingding;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.impl.CorpTokenService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "钉钉corp获取accesstoken")
@RestController
@AllArgsConstructor
@RequestMapping("invoice/")
public class DingCorpAccessTokenController {
    private static final Logger bizlogger = LoggerFactory.getLogger(DingCorpAccessTokenController.class);
    @Autowired
    private CorpTokenService corpTokenService;


    @RequestMapping(value = "/getCorpAccessToken", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getAccessToken(@RequestParam(value = "corpId", required = true) String corpId) {
        String token = null;
        try {
            token = corpTokenService.getCorpToken(corpId);
        } catch (Exception e) {
            bizlogger.error(e.getMessage(), e);
            return AjaxResult.error("获取失败");
        }
        Map<String, String> tokenMap = new HashMap<>();
        tokenMap.put("access_token", token);
        return AjaxResult.success("success", tokenMap);
    }


}
